# core/database/schema.py
from typing import Optional

from pydantic import BaseModel,Field,model_validator

class CharacterBase(BaseModel):
    name: str
    cn_name: str
    image: str
    tag: str

class CharacterCreate(CharacterBase):
    pass

class CharacterUpdate(BaseModel):
    name: str
    cn_name: str | None = None
    tag: str | None = None

class ActionBase(BaseModel):
    """动作数据基础模型"""
    name: str
    cn_name: str
    image: str
    tag: str

class ActionCreate(ActionBase):
    """创建动作请求模型"""
    pass

class ActionUpdate(BaseModel):
    """更新动作请求模型"""
    name: str  # 必须提供名称用于定位记录
    cn_name: Optional[str] = None
    tag: Optional[str] = None


class CollectBase(BaseModel):
    name: str
    cn_name: str
    des: str
    image: str

class CollectCreate(CollectBase):
    pass

class CollectUpdate(BaseModel):
    id: Optional[int] = None
    name: Optional[str]
    cn_name: Optional[str]
    des: Optional[str]
    image: Optional[str]

class StyleBase(BaseModel):
    name: str
    cn_name: str
    des: str
    image: str

class StyleCreate(StyleBase):
    pass

class StyleUpdate(BaseModel):
    id: Optional[int] = None
    name: Optional[str]
    cn_name: Optional[str]
    des: Optional[str]
    image: Optional[str]


class TagBase(BaseModel):
    group: str = Field(..., min_length=2, max_length=20)
    name: str = Field(..., min_length=2, max_length=20)
    tag: str = Field(..., min_length=2, max_length=20)
    description: str = Field(..., min_length=5)

class TagCreate(TagBase):
    pass

class TagUpdate(BaseModel):
    group: Optional[str] = Field(None, min_length=2, max_length=20)
    name: Optional[str] = Field(None, min_length=2, max_length=20)
    tag: Optional[str] = Field(None, min_length=2, max_length=20)
    description: Optional[str] = Field(None, min_length=5)

class BatchOperation(BaseModel):
    type: str
    data: dict

class Pagination(BaseModel):
    page: int = Field(1, ge=1)
    page_size: int = Field(10, ge=1, le=100)